#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e4 + 5;
const int M = 105;

int n, m, row, col;
char s[N][M];
int Next[N];

int cnt[M];
bool check(int i, int j) {
  rep(k, j, m - 1) if (s[i][k] != s[i][k - j]) return false;
  return true;
}
int solve_col() {
  rep(j, 1, m - 1) {
    int cnt = 0;
    rep(i, 0, n - 1) if (check(i, j)) cnt++;
    if (cnt == n) return j;
  }
  return m;
}
bool cmp_row(int i, int j) {
  rep(k, 0, col - 1) if (s[i][k] != s[j][k]) return false;
  return true;
}
int solve_row() {
  int t = -1;
  int i = 0;
  Next[i] = t;
  while (i < n) {
    if (t < 0 || cmp_row(t, i)) {
      t++, i++;
      Next[i] = t;
    } else {
      t = Next[t];
    }
  }
  return n - Next[n];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 0, n - 1) rep(j, 0, m - 1) cin >> s[i][j];
  col = solve_col();
  row = solve_row();
  cout << row * col << endl;
  return 0;
}